<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>countWeekDaysBetween</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const countWeekDaysBetween = (startDate, endDate) =>
            Array.from({ length: (endDate - startDate) / (1000 * 3600 * 24) }).reduce(
                count => {
                    if (startDate.getDay() % 6 !== 0) {
                        count++;
                    }
                    startDate = new Date(startDate.setDate(startDate.getDate() + 1));
                    return count;
                },
                0
            );
        console.log(countWeekDaysBetween(new Date('Oct 05, 2020'), new Date('Oct 06, 2020'))); // 1
        console.log(countWeekDaysBetween(new Date('Oct 05, 2020'), new Date('Oct 14, 2020'))); // 7
    </script>
</body>

</html>